package com.xunqi.mall.listener;

import com.google.gson.Gson;
import com.xunqi.mall.pojo.PayInfo;
import com.xunqi.mall.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Description:
 * @Created: with IntelliJ IDEA.
 * @author: 夏沫止水
 * @createTime: 2020-05-14 13:57
 **/

@Component
@RabbitListener(queues = "payNotify")
@Slf4j
public class PayMsgListener {

    @Resource
    private OrderService orderService;

    @RabbitHandler
    public void process(String msg) {
        log.info("【接收到消息】 => {}",msg);

        PayInfo payInfo = new Gson().fromJson(msg, PayInfo.class);
        if (payInfo.getPlatformStatus().equals("SUCCESS")) {
            //修改订单里的状态
            orderService.paid(payInfo.getOrderNo());
        }
    }

}
